package tjs.org.springLoader.annotion;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;
import tjs.org.springLoader.config.AutoReoladerConfiguration;
import tjs.org.springLoader.reloader.IocReloader;
import tjs.org.springLoader.reloader.MybatisReloader;
import tjs.org.springLoader.reloader.WebMvcReloader;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Nicky.Tang on 2021/9/29 5:19 下午
 *
 * @since 02.12.10
 */
public class EnableAutoResetLoaderImportSelector implements ImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        Map<String, Object> enableDkdTransactional = annotationMetadata.getAnnotationAttributes(EnableAutoResetLoader.class.getName());
        boolean autoReset = Boolean.valueOf(enableDkdTransactional.get("autoReset").toString());
        if (!autoReset) {
            return new String[0];
        }

        List<String> resBeans = new ArrayList<>();
        resBeans.add(AutoReoladerConfiguration.class.getName());

        // 自定义的一些reloader
        resBeans.add(IocReloader.class.getName());
        resBeans.add(MybatisReloader.class.getName());
        resBeans.add(WebMvcReloader.class.getName());
        
        return resBeans.toArray(new String[resBeans.size()]);
    }
}
